home *** CD-ROM | disk | FTP | other *** search
/ Day Cry / Day Cry CD.bin / oh_towns / taropyon / splib / splib.lzh / PRG / LHX / LIST.C < prev    next >
C/C++ Source or Header  |  1992-12-08  |  3KB  |  130 lines

  1. /***********************************************************
  2.         list.c -- list files in archive
  3. ***********************************************************/
  4. #include    "lh386.h"
  5.  
  6. #include    <stdio.h>
  7. #include    <string.h>
  8. #include    <time.h>
  9. #include    "lh.h"
  10.  
  11. #ifdef    __HIGHC__
  12. #    pragma    On(Align_labels);
  13. #endif
  14.  
  15.  
  16. static int    filecount;
  17. static long originalsize, packedsize;
  18.  
  19. void        initlist(void)
  20. {
  21.     filecount = originalsize = packedsize = 0;
  22.     if (flg_n == 0)
  23.     {
  24.         LHX_printf("  Name          Original    Packed  Ratio"
  25.                    "   Date     Time   Attr Type  CRC\n");
  26.         LHX_printf("--------------  --------  -------- ------"
  27.                    " -------- -------- ---- ----- ----\n");
  28.     }
  29. }
  30.  
  31. static void expanddate(char *buf, time_t t, ulong org, ulong pac)
  32. {
  33.     struct tm  *tm;
  34.     int         rt;
  35.  
  36.     tm = localtime(&t);
  37.     rt = ratio(pac, org, 3);
  38.     sprintf(buf + 14, "%10lu%10lu %3d.%1d%% "
  39.             "%02d/%02d/%02d %02d:%02d:%02d",
  40.             org, pac, rt / 10, rt % 10,
  41.             tm->tm_year % 100,
  42.             tm->tm_mon + 1,
  43.             tm->tm_mday,
  44.             tm->tm_hour,
  45.             tm->tm_min,
  46.             tm->tm_sec);
  47. }
  48.  
  49. void        list(void)
  50. {
  51.     char        buf[79], *p, *q;
  52.     static char attr[7] = "ohs--a";
  53.     int         i, j, k;
  54.  
  55.     p = hpb.filename;
  56.     q = hpb.pathname;
  57.     if (flg_n == 0)
  58.     {
  59.         memset(buf, ' ', 14);
  60.         expanddate(buf, hpb.utc, hpb.original, hpb.packed);
  61.         sprintf(buf + 59, " ---w       %04X", hpb.filecrc);
  62.         memcpy(&buf[65], hpb.method, 5);
  63.         for (i = 0, j = 1; i < 6; i++, j <<= 1)
  64.         {                        /* attributes */
  65.             if (hpb.attr & j)
  66.             {
  67.                 k = attr[i];
  68.                 if (i <= 2)
  69.                 {
  70.                     buf[63 - i] = k;
  71.                 } else
  72.                 {
  73.                     buf[60] = k;
  74.                 }
  75.             }
  76.         }
  77.         if (hpb.level < 0)
  78.         {
  79.             memset(&buf[71], '*', 4);    /* if no CRC supported */
  80.         }
  81.         if (flg_x)
  82.         {
  83.             LHX_puts(q);            /* display in 2 lines */
  84.             LHX_puts("\r\n");
  85.         } else
  86.         {
  87.             if (p != q)
  88.             {                    /* display in one line */
  89.                 *buf = '+';
  90.             }
  91.             memcpy(&buf[2], p, strlen(p));
  92.         }
  93.         LHX_puts(buf);
  94.         LHX_puts("\r\n");
  95.         filecount++;
  96.         originalsize += hpb.original;
  97.         packedsize += hpb.packed;
  98.     } else
  99.     {
  100.         if (flg_x)
  101.         {
  102.             LHX_puts(q);
  103.         } else
  104.         {
  105.             LHX_puts(p);
  106.         }
  107.         LHX_puts("\r\n");
  108.     }
  109. }
  110.  
  111. void        endlist(time_t arctime)
  112. {
  113.     char        buf[79];
  114.  
  115.     if (flg_n == 0)
  116.     {
  117.         if (filecount)
  118.         {
  119.             LHX_printf("--------------  --------  -------- ------"
  120.                        " -------- --------\n");
  121.             sprintf(buf, "   %3d files  ", filecount);
  122.             expanddate(buf, arctime, originalsize, packedsize);
  123.             LHX_puts(buf);
  124.         } else
  125.         {
  126.             LHX_printf("  no file\n");
  127.         }
  128.     }
  129. }
  130.